package com.veeder.datacollection.rs232.response.handler;

import com.veeder.datacollection.exception.SyntaxException;
import com.veeder.datacollection.rs232.response.MagProbeFloatSize;
import com.veeder.datacollection.rs232.response.TankResponseReport;
import com.veeder.datacollection.util.DateUtil;

public class RS62FRspHandler extends CmdRspParser{

	@Override
	public TankResponseReport<MagProbeFloatSize> parseCoreResponse(String coreResponse) throws SyntaxException {
		TankResponseReport<MagProbeFloatSize> result=null;
		try {
			result =new TankResponseReport<MagProbeFloatSize>();
			int position = 6;
			result.setTlsSysDate(
					DateUtil.convertToDate(coreResponse.substring(position, position += 10), DateUtil.DateFormat1));
			while (position < coreResponse.length()) {
				int tankId = Integer.parseInt(coreResponse.substring(position, position += 2));
				int floatSizeIndex= Integer.parseInt((coreResponse.substring(position, position +=1)));
				MagProbeFloatSize floatSize = MagProbeFloatSize.getEnum(floatSizeIndex);
				result.setTankReponse(tankId, floatSize);
			}
		} catch (Exception e) {
			throw new SyntaxException(e.toString());
		}

		return result;
	}

}
